﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using System.Data;

public partial class EarlyWarning_TradePreWarning_CL : BasePage
{
    public EarlyWarning_TradePreWarning_CL()
    { }

    int totalrecord = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }
    private void BindData()
    {
        //HZ.Supervise.IBLL.IBLL_PreWarning iPreWarning = HZ.Supervise.BLLFactory.IBLL_PreWarning();
        //HZ.Supervise.Model.TradePreWarning mTradePreWarning = new TradePreWarning();
        //mTradePreWarning.IsUsing = true;
        //DataTable dt1 = new DataTable();
        //clsTradePreWarning obj = new clsTradePreWarning();
        //dt1 = obj.GetTradePreWarning(this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out totalrecord);//iPreWarning.GetTradePreWarning_CL(mTradePreWarning, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out totalrecord);
        //HZ.Supervise.IBLL.IBLL_PreWarning iPreWarning = HZ.Supervise.BLLFactory.IBLL_PreWarning();
        //HZ.Supervise.Model.DrugPreWarning mDrugPreWarning = new DrugPreWarning();
        //mDrugPreWarning.IsUsing = true;
        //DataTable dt2 = new DataTable();
        //dt2 = iPreWarning.GetDrugPreWarning_CL(mDrugPreWarning, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out totalrecord);
        //DataTable DTSourse = new DataTable();
        //DTSourse = UniteDataTable(dt1, dt2, "DTSourse");
        //this.gvwInfo.DataSource = DTSourse;
        //this.gvwInfo.DataBind();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindData();
    }

    //两个结构不同的DT合并
    /// <summary>
    /// 将两个列不同的DataTable合并成一个新的DataTable
    /// </summary>
    /// <param name="dt1">表1</param>
    /// <param name="dt2">表2</param>
    /// <param name="DTName">合并后新的表名</param>
    /// <returns></returns>
    private DataTable UniteDataTable(DataTable dt1, DataTable dt2, string DTName)
    {
        DataTable dt3 = dt1.Clone();
        for (int i = 0; i < dt2.Columns.Count; i++)
        {
            dt3.Columns.Add(dt2.Columns[i].ColumnName);
        }
        object[] obj = new object[dt3.Columns.Count];

        for (int i = 0; i < dt1.Rows.Count; i++)
        {
            dt1.Rows[i].ItemArray.CopyTo(obj, 0);
            dt3.Rows.Add(obj);
        }

        if (dt1.Rows.Count >= dt2.Rows.Count)
        {
            for (int i = 0; i < dt2.Rows.Count; i++)
            {
                for (int j = 0; j < dt2.Columns.Count; j++)
                {
                    dt3.Rows[i][j + dt1.Columns.Count] = dt2.Rows[i][j].ToString();
                }
            }
        }
        else
        {
            DataRow dr3;
            for (int i = 0; i < dt2.Rows.Count - dt1.Rows.Count; i++)
            {
                dr3 = dt3.NewRow();
                dt3.Rows.Add(dr3);
            }
            for (int i = 0; i < dt2.Rows.Count; i++)
            {
                for (int j = 0; j < dt2.Columns.Count; j++)
                {
                    dt3.Rows[i][j + dt1.Columns.Count] = dt2.Rows[i][j].ToString();
                }
            }
        }
        dt3.TableName = DTName; //设置DT的名字
        return dt3;
    }
    protected void gvwInfo_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string strWarningLevel = e.Row.Cells[8].Text;
            switch (strWarningLevel)
            {
                case "0":
                    e.Row.Cells[8].Text = "一级预警";
                    break;
                case "1":
                    e.Row.Cells[8].Text = "二级预警";
                    break;
                case "2":
                    e.Row.Cells[8].Text = "三级预警";
                    break;
            }
            string strWarningType = e.Row.Cells[7].Text;
            switch (strWarningLevel)
            {
                case "0":
                    e.Row.Cells[7].Text = "医院已提交采购单企业未确认";
                    break;
                case "1":
                    e.Row.Cells[7].Text = "企业已确认定单医院未入库";
                    break;
                case "2":
                    e.Row.Cells[7].Text = "企业已开发票中心未审核";
                    break;
                case "3":
                    e.Row.Cells[7].Text = "医院已提交退货单企业未确认";
                    break;
                case "4":
                    e.Row.Cells[7].Text = "医院已提交回款单企业未确认";
                    break;
                case "5":
                    e.Row.Cells[7].Text = "医院已入库未回款";
                    break;
            }
        }

    }
    protected void btnExcel_Click(object sender, EventArgs e)
    {
        //DataTable dt1 = new DataTable();
        //clsTradePreWarning obj = new clsTradePreWarning();
        //dt1 = obj.GetTradePreWarning(this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out totalrecord);//iPreWarning.GetTradePreWarning_CL(mTradePreWarning, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out totalrecord);
        //HZ.Supervise.IBLL.IBLL_PreWarning iPreWarning = HZ.Supervise.BLLFactory.IBLL_PreWarning();
        //HZ.Supervise.Model.DrugPreWarning mDrugPreWarning = new DrugPreWarning();
        //mDrugPreWarning.IsUsing = true;
        //DataTable dt2 = new DataTable();
        //dt2 = iPreWarning.GetDrugPreWarning_CL(mDrugPreWarning, 0,0, out totalrecord);
        //DataTable DTSourse = new DataTable();
        //DTSourse = UniteDataTable(dt1, dt2, "DTSourse");

        //ExportFile.Instance.ExportData(DTSourse, gvwInfo, this.Page);
    }
}
